<?php 
session_start();
if (isset($_POST['pyes']) && isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
    $pyes=trim(addslashes($_POST['pyes']));
    $page=trim(addslashes($_POST['p']));
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	$sql="select id from zhang where openid='".$openid."'  limit 0, 1";
	$query=$mysqli->query($sql);
    if($query->num_rows>0){
        if ('p2' == $page){
            $mysqli->query("update `zhang` set `p2`='".$pyes."'  where openid='".$openid."'");
        }
        if ('p3' == $page){
            $mysqli->query("update `zhang` set `p3`='".$pyes."'  where openid='".$openid."'"); 
        }
        if ('p4' == $page){
            $mysqli->query("update `zhang` set `p4`='".$pyes."'  where openid='".$openid."'");
        }
        
    }else{
        if ('p2' == $page){
            $mysqli->query("INSERT INTO `zhang` (`openid`,`p2`,`createtime`) VALUES ('".$openid."','".$pyes."','".date("Y-m-d H:i:s")."') ");
        }
    }
 
    echo json_encode(array('s'=>'ok'));
    $mysqli->close();

}else{
    $msg=json_encode(array('s'=>'n'));
}
?>